#include "internal_foundation.h"
#include "foundation.h"

namespace NS_TIEC {
  Position Position::plusLength(UInt32 length) {
    return {line, column + length, index + length};
  }

  TiecodeFileSource::TiecodeFileSource(const File& file) : file_(file), child_sources_({}) {
  }

  TiecodeFileSource::TiecodeFileSource(const File& file, List<File> child_files): file_(file) {
    for (const auto& item: child_files) {
      auto source = MAKE_PTR<TiecodeFileSource>(item);
      child_sources_.add(source);
    }
  }

  String TiecodeFileSource::getName() {
    return file_.getName();
  }

  UInt64 TiecodeFileSource::lastModified() {
    return file_.lastUpdateTime();
  }

  String TiecodeFileSource::readContent() {
    return file_.readString();
  }

  Uri TiecodeFileSource::getUri() {
    return file_.toUri();
  }

  String TiecodeFileSource::getPath() {
    return file_.getPath();
  }

  List<PTR<TiecodeSource>> TiecodeFileSource::childSources() {
    return child_sources_;
  }

  FileCategory TiecodeFileSource::getCategory() {
    return FileCategory::Source;
  }

  StringName::StringName(const String& str): str_(str) {
  }

  String StringName::asString() {
    return str_;
  }

  UInt64 StringName::length() {
    return str_.length();
  }

  UInt64 StringName::indexOf(char ch) {
    return str_.find(ch);
  }

  bool StringName::contentSameAs(const String& text) {
    return str_ == text;
  }

  Diagnostic::Diagnostic() {}

  Diagnostic::Diagnostic(const String& message) : message(message) {}

  Diagnostic::Diagnostic(const String& message, LogLevel level): message(message), level(level) {
  }

  Diagnostic::Diagnostic(const String& uri, const Range& range, const String& message, const String& key) : uri(uri),
                                                                                                         range(range),
                                                                                                         message(
                                                                                                             message),
                                                                                                         key(key) {}

  Diagnostic::Diagnostic(const String& uri, const Range& range, const String& key, const String& message, LogLevel level)
      : uri(uri), range(range), key(key), message(message), level(level) {}
}